package com.fcscs.cservice.client.main.configuration.activitylog;

import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.fcscs.core.common.MainPaginationSearchModel;
import com.fcscs.core.common.authority.UserAuthority;
import com.fcscs.core.gwt.common.CoreConstants;
import com.fcscs.core.gwt.common.SearchExecutor;
import com.fcscs.core.gwt.common.ui.FcsFields.EasyClearCombobox;
import com.fcscs.core.gwt.common.ui.FcsFields.FormButton;
import com.fcscs.core.gwt.common.ui.FcsPanel;
import com.fcscs.core.gwt.common.ui.IEFriendlyDateField;
import com.fcscs.cservice.client.common.CServiceConstants;
import com.fcscs.cservice.client.common.model.configuration.reservation.PropertyIdNameModelData;
import com.fcscs.cservice.client.common.model.reservation.ReservationViewModelData;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Widget;

public class ActivityLogPanel extends FcsPanel {
	private VerticalPanel vp;
	private FormPanel myFormPanel;
	private HorizontalPanel hp1;
	private LayoutContainer lc1;
	private Label propLab;
	private EasyClearCombobox<PropertyIdNameModelData> propCombox;
	private ListStore<PropertyIdNameModelData> propStore;
	private CheckBox showInactiveUser;
	private LayoutContainer lc2;
	private Label activityLab;
	private EasyClearCombobox<PropertyIdNameModelData> activiGroupCombox;
	private ListStore<PropertyIdNameModelData> actiGroupStore;
	private HorizontalPanel hp2;
	private HorizontalPanel propHp;
	private HorizontalPanel activiGroupHp;
	private Label activityByLab;
	private HorizontalPanel activiByHp;
	private EasyClearCombobox<PropertyIdNameModelData> activiByCombox;
	private ListStore<PropertyIdNameModelData> actiByStore;
	private HorizontalPanel hp3;
	private LayoutContainer lc3;
	private Label activityTypeLab;
	private HorizontalPanel activityTypeHp;
	private EasyClearCombobox<PropertyIdNameModelData> activityTypeCombox;
	private ListStore<PropertyIdNameModelData> activityTypeStore;
	private Label activityForLab;
	private HorizontalPanel activityForHp;
	private EasyClearCombobox<PropertyIdNameModelData> activityForCombox;
	private ListStore<PropertyIdNameModelData> activityForStore;
	private HorizontalPanel hp4;
	private LayoutContainer lc4;
	private IEFriendlyDateField fromDate;
	private HorizontalPanel fromDateHp;
	private Label activityfromDateLab;
	private Label toDateLab;
	private HorizontalPanel toDateHp;
	private IEFriendlyDateField toDate;
	private FormButton searchBtn;
	private ActivityLogsGrid grid;
	private ActivityDetailDialog activityDetailDialog;
	private HorizontalPanel hp5;

	public ActivityLogPanel(String id) {
		super(id);
	}

	@Override
	public void init() {
		if (vp == null) {
			vp = new VerticalPanel();
			vp.setId("ActivityLogPanel_vp");
			vp.setSpacing(5);
			// search category form
			searchForm();

			// grid
			grid = new ActivityLogsGrid(CServiceConstants.CSERVICE_CONSTANTS.activityLogs(),
					new SearchExecutor<ReservationViewModelData, MainPaginationSearchModel>() {

						@Override
						public void doSearch(MainPaginationSearchModel searchModel,
								AsyncCallback<BasePagingLoadResult<ReservationViewModelData>> callback) {

						}
					});
			vp.add(grid);
			add(vp);
		}

	}

	private void searchForm() {
		myFormPanel = new FormPanel();
		myFormPanel.setHeading(CServiceConstants.CSERVICE_CONSTANTS.searchCriteria());
		myFormPanel.setFrame(true);
		myFormPanel.setId("ActivityLogPanel_myFormPanel");
		myFormPanel.setSize(740, 150);
		vp.add(myFormPanel);

		hp1 = new HorizontalPanel();
		hp1.setId("ActivityLogPanel_hp1");
		myFormPanel.add(hp1);

		lc1 = new LayoutContainer();
		lc1.setId("ActivityLogPanel_lc1");
		lc1.setLayout(new ColumnLayout());
		hp1.add(lc1);

		propLab = new Label(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.property(),
				CoreConstants.REQURIED_FIELD_LABEL));
		propLab.setId("ActivityLogPanel_prosLab");
		lc1.add(propLab, new ColumnData(120));

		propHp = new HorizontalPanel();
		propHp.setId("ActivityLogPanel_hp1");
		lc1.add(propHp, new ColumnData(350));

		propCombox = new EasyClearCombobox<PropertyIdNameModelData>();
		propCombox.setDisplayField(CoreConstants.FULLTNAME);
		propStore = new ListStore<PropertyIdNameModelData>();
		propCombox.setWidth(200);
		propCombox.setStore(propStore);
		propCombox.setId("ActivityLogPanel_prosComBox");
		propCombox.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.choosePro());
		propCombox.setTriggerAction(TriggerAction.ALL);
		propCombox.setForceSelection(true);
		propCombox.setFireChangeEventOnSetValue(true);
		propHp.add(propCombox);

		showInactiveUser = new CheckBox();
		showInactiveUser.setId("ActivityLogPanel_showInactiveUser");
		showInactiveUser.setBoxLabel(CServiceConstants.CSERVICE_CONSTANTS.showInactiveUserList());
		lc1.add(showInactiveUser, new ColumnData(200));

		hp2 = new HorizontalPanel();
		hp2.setId("ActivityLogPanel_hp2");
		myFormPanel.add(hp2);

		lc2 = new LayoutContainer();
		lc2.setStyleAttribute(CServiceConstants.CSS_MARGINTOP, "5px");
		lc2.setId("ActivityLogPanel_lc2");
		lc2.setLayout(new ColumnLayout());
		hp2.add(lc2);

		activityLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.activityGroup()
				+ CServiceConstants.FIELD_SEP);
		activityLab.setId("ActivityLogPanel_activityLab");
		lc2.add(activityLab, new ColumnData(120));

		activiGroupHp = new HorizontalPanel();
		activiGroupHp.setId("ActivityLogPanel_activiGroupHp");
		lc2.add(activiGroupHp, new ColumnData(250));

		activiGroupCombox = new EasyClearCombobox<PropertyIdNameModelData>();
		activiGroupCombox.setDisplayField(CoreConstants.FULLTNAME);
		actiGroupStore = new ListStore<PropertyIdNameModelData>();
		activiGroupCombox.setWidth(200);
		activiGroupCombox.setStore(actiGroupStore);
		activiGroupCombox.setId("ActivityLogPanel_actiGroupCombox");
		activiGroupCombox.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.choosePro());
		activiGroupCombox.setTriggerAction(TriggerAction.ALL);
		activiGroupCombox.setForceSelection(true);
		activiGroupCombox.setFireChangeEventOnSetValue(true);
		activiGroupHp.add(activiGroupCombox);

		activityByLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.activityBy()
				+ CServiceConstants.FIELD_SEP);
		activityByLab.setId("ActivityLogPanel_activityByLab");
		lc2.add(activityByLab, new ColumnData(100));

		activiByHp = new HorizontalPanel();
		activiByHp.setId("ActivityLogPanel_activiByHp");
		lc2.add(activiByHp, new ColumnData(200));

		activiByCombox = new EasyClearCombobox<PropertyIdNameModelData>();
		activiByCombox.setDisplayField(CoreConstants.FULLTNAME);
		actiByStore = new ListStore<PropertyIdNameModelData>();
		activiByCombox.setWidth(200);
		activiByCombox.setStore(actiByStore);
		activiByCombox.setId("ActivityLogPanel_activiByCombox");
		activiByCombox.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.choosePro());
		activiByCombox.setTriggerAction(TriggerAction.ALL);
		activiByCombox.setForceSelection(true);
		activiByCombox.setFireChangeEventOnSetValue(true);
		activiByHp.add(activiByCombox);

		hp3 = new HorizontalPanel();
		hp3.setId("ActivityLogPanel_hp3");
		myFormPanel.add(hp3);

		lc3 = new LayoutContainer();
		lc3.setStyleAttribute(CServiceConstants.CSS_MARGINTOP, "5px");
		lc3.setId("ActivityLogPanel_lc3");
		lc3.setLayout(new ColumnLayout());
		hp3.add(lc3);

		activityTypeLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.activityType()
				+ CServiceConstants.FIELD_SEP);
		activityTypeLab.setId("ActivityLogPanel_activityTypeLab");
		lc3.add(activityTypeLab, new ColumnData(120));

		activityTypeHp = new HorizontalPanel();
		activityTypeHp.setId("ActivityLogPanel_activityTypeHp");
		lc3.add(activityTypeHp, new ColumnData(250));

		activityTypeCombox = new EasyClearCombobox<PropertyIdNameModelData>();
		activityTypeCombox.setDisplayField(CoreConstants.FULLTNAME);
		activityTypeStore = new ListStore<PropertyIdNameModelData>();
		activityTypeCombox.setWidth(200);
		activityTypeCombox.setStore(activityTypeStore);
		activityTypeCombox.setId("ActivityLogPanel_activiByCombox");
		activityTypeCombox.setTriggerAction(TriggerAction.ALL);
		activityTypeCombox.setForceSelection(true);
		activityTypeCombox.setFireChangeEventOnSetValue(true);
		activityTypeHp.add(activityTypeCombox);

		activityForLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.activityFor()
				+ CServiceConstants.FIELD_SEP);
		activityForLab.setId("ActivityLogPanel_activityForLab");
		lc3.add(activityForLab, new ColumnData(100));

		activityForHp = new HorizontalPanel();
		activityForHp.setId("ActivityLogPanel_activityForHp");
		lc3.add(activityForHp, new ColumnData(200));

		activityForCombox = new EasyClearCombobox<PropertyIdNameModelData>();
		activityForCombox.setDisplayField(CoreConstants.FULLTNAME);
		activityForStore = new ListStore<PropertyIdNameModelData>();
		activityForCombox.setWidth(200);
		activityForCombox.setStore(activityForStore);
		activityForCombox.setId("ActivityLogPanel_activiByCombox");
		activityForCombox.setTriggerAction(TriggerAction.ALL);
		activityForCombox.setForceSelection(true);
		activityForCombox.setFireChangeEventOnSetValue(true);
		activityForHp.add(activityForCombox);

		hp4 = new HorizontalPanel();
		hp4.setId("ActivityLogPanel_hp4");
		myFormPanel.add(hp4);

		lc4 = new LayoutContainer();
		lc4.setId("ActivityLogPanel_lc4");
		lc4.setStyleAttribute(CServiceConstants.CSS_MARGINTOP, "5px");
		lc4.setLayout(new ColumnLayout());
		hp4.add(lc4);

		activityfromDateLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.activityFromDate()
				+ CServiceConstants.FIELD_SEP);
		activityfromDateLab.setId("ActivityLogPanel_activityfromDateLab");
		lc4.add(activityfromDateLab, new ColumnData(120));

		fromDateHp = new HorizontalPanel();
		fromDateHp.setId("ActivityLogPanel_fromDateHp");
		lc4.add(fromDateHp,new ColumnData(250));

		fromDate = new IEFriendlyDateField();
		fromDate.setId("ActivityLogPanel_fromDate");
		fromDate.setMessageTarget("tooltip");
		fromDate.setEditable(false);
		fromDateHp.add(fromDate);

		toDateLab = new Label(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.to(),
				CoreConstants.CORE_CONSTANTS.date() + CServiceConstants.FIELD_SEP));
		toDateLab.setId("ActivityLogPanel_toDateLab");
		lc4.add(toDateLab, new ColumnData(100));

		toDateHp = new HorizontalPanel();
		toDateHp.setId("ActivityLogPanel_fromDateHp");
		lc4.add(toDateHp, new ColumnData(200));

		toDate = new IEFriendlyDateField();
		toDate.setId("ActivityLogPanel_toDate");
		toDate.setMessageTarget("tooltip");
		toDate.setEditable(false);
		toDateHp.add(toDate);

		searchBtn = new FormButton(CoreConstants.CORE_CONSTANTS.search());
		searchBtn.setId("ActivityLogPanel_searchBtn");
//		lc4.add(searchBtn, new ColumnData(60));
		
		hp5 = new HorizontalPanel();
		hp5.setId("ActivityLogPanel_hp5");
		hp5.setSpacing(5);
		hp5.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT,"610px");
		myFormPanel.add(hp5);
		
		searchBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				activityDetailDialog = ActivityDetailDialog.getInstance();
				activityDetailDialog.show();
			}
		});
		hp5.add(searchBtn);
	}

	@Override
	public UserAuthority getRequiredAuthority() {
		return null;
	}

	@Override
	protected Widget getViewPanel() {
		return null;
	}

	@Override
	public void onShow() {

	}

	@Override
	public boolean onHide() {
		return true;
	}

}
